<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/6/5
 * Time: 11:19
 */

namespace app\admin\controller;


use app\admin\model\LeaveWord;

class Message extends Base
{
    //============================================留言列表
    public function lists(){
        return $this->fetch();
    }

    //============================================留言数据
    public function data($page,$limit){
        $where = '';
        $data = LeaveWord::where($where)->page($page,$limit)->select()->toArray();
        foreach ($data as $key=>$v){
            $data[$key]['time']=date('Y-m-d H:i:s',$v['time']);
        }
        $count = LeaveWord::count();
        $result = [
            'code'=>0,
            'msg'=>'返回成功',
            'count'=>$count,
            'data'=>$data
        ];
        return json($result);
    }

    //=============================================删除留言
    public function del(){
        $id = input('post.id');
        $ret = LeaveWord::destroy($id);
        if (!$ret){
            return json(['code'=>0,'msg'=>'删除失败']);
        }
        return json(['code'=>1,'msg'=>'删除成功']);
    }
}